/*
 * $Id$
 */

package py.windmill.util;

/**
 *
 * @author py
 */
public class AppFogDatabaseFactory {

    private JsonObject _credentials;

    public AppFogDatabaseFactory() {
        this(System.getenv("VCAP_SERVICES"));
    }

    public AppFogDatabaseFactory(final String s) {
        _credentials = JsonObject.object(s)
          .getArray("mysql-5.1").getObject(0).getObject("credentials");;
    }
    
    public Database newDatabase() {
        return Database.mysql().setHost(_credentials.getString("host"))
                .setName(_credentials.getString("name"))
                .setPort(_credentials.getInt("port"))
                .setUsername(_credentials.getString("username"))
                .setPassword(_credentials.getString("password"));
    }

}
